package com.useeinfo.oa.modules.task.entity;

import com.alibaba.fastjson.JSONObject;
import com.useeinfo.framework.extend.entity.SuperClassEntity;
import com.useeinfo.framework.sugar.tools.StringConverters;
import com.useeinfo.oa.modules.base.entity.Enterprise;
import com.useeinfo.oa.modules.security.entity.SystemUser;
import com.useeinfo.oa.modules.task.enums.TaskOrderLogOperationEnum;

import javax.persistence.*;

/**
 * @auther: bin.liu
 * @Date: 2019/7/1 9:49
 * @Description: 任务工单操作日志
 */
@Entity
@Table(name = "task_order_log")
public class TaskOrderLog extends SuperClassEntity<TaskOrderLog> {

    @ManyToOne
    @JoinColumn(name = "user_id")
    private SystemUser systemUser;

    private String userName;

    /**
     * 操作详情
     */
    private String detail;

    /**
     * 备注
     */
    private String remark;

    @ManyToOne
    @JoinColumn(name = "enterprise_id")
    private Enterprise enterprise;

    /**
     * 工单状态
     */
    @Enumerated(value = EnumType.STRING)
    @Column(name = "task_order_operation")
    private TaskOrderLogOperationEnum taskOrderLogOperationEnum;

    @ManyToOne
    @JoinColumn(name = "task_order_id")
    private TaskOrder taskOrder;

    public SystemUser getSystemUser() {
        return systemUser;
    }

    public void setSystemUser(SystemUser systemUser) {
        this.systemUser = systemUser;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getDetail() {
        return detail;
    }

    public void setDetail(String detail) {
        this.detail = detail;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public Enterprise getEnterprise() {
        return enterprise;
    }

    public void setEnterprise(Enterprise enterprise) {
        this.enterprise = enterprise;
    }

    public TaskOrderLogOperationEnum getTaskOrderLogOperationEnum() {
        return taskOrderLogOperationEnum;
    }

    public void setTaskOrderLogOperationEnum(TaskOrderLogOperationEnum taskOrderLogOperationEnum) {
        this.taskOrderLogOperationEnum = taskOrderLogOperationEnum;
    }

    public TaskOrder getTaskOrder() {
        return taskOrder;
    }

    public void setTaskOrder(TaskOrder taskOrder) {
        this.taskOrder = taskOrder;
    }

    @Override
    public JSONObject toJSONObject() {
        JSONObject jsonObject = super.toJSONObject();
        jsonObject.put("userName", StringConverters.null2String(getUserName()));
        jsonObject.put("operation", getTaskOrderLogOperationEnum().getName());
        jsonObject.put("detail", StringConverters.null2String(getDetail()));
        jsonObject.put("returnReason",StringConverters.null2String(getRemark()));
        return jsonObject;
    }
}
